import io, requests

base_url = 'http://8.156.82.84:8088'
# base_url = 'http://localhost:8088'

class MsServerApi:
    def upload_bytes(self, file_bytes: bytes, filename: str,
                     url: str = base_url + "/resource/oss/upload/internal"):
        if bytes is None:
            return None
        files = {
            "file": (filename, io.BytesIO(file_bytes), "multipart/form-data")
        }
        resp = requests.post(url, files=files)
        if resp.status_code == 200:
            return resp.json().get("data")
        else:
            raise Exception(f"Upload failed: {resp.status_code}, {resp.text}")
